Monado Runtime源码结构分析
源码地址
monado的源码下载地址:https://gitlab.freedesktop.org/monado/monado
Monado source tree
ReadMe.md的部分已经有阐释了整个工程的目录概要:
src/xrt/include
- headers that define the internal interfaces of Monado.src/xrt/compositor
- code for doing distortion and driving the display hardware of a device.src/xrt/auxiliary
- utilities and other larger components.src/xrt/drivers
- hardware drivers.src/xrt/state_trackers/oxr
- OpenXR API implementation.src/xrt/targets
- glue code and build logic to produce final binaries.src/external
- a small collection of external code and headers.
gradle for Android
参考根目录下的settings.gradle
文件,可以看出整个工程其实是包含了4个部分的:
- rootProject.name = ‘monado’
- include
':src:xrt:auxiliary:android'
- include
':src:xrt:ipc:android'
- include
':src:xrt:targets:android_common'
- include
':src:xrt:targets:openxr_android'
这个是我们非常熟悉的Android
工程的结构了,根据以往的经验,我们需要从com.android.application
的工程入手进行分析。
openxr_android
整个工程编译apk的主module是openxr_android,因此先分析openxr_android/build.gradle:
build.gradle
|
|
在这里有三个关键点:
整个工程的CMakeLists.txt是
"${rootDir}/CMakeLists.txt"
,也即monado/CMakeLists.txt
区分了productFlavors,包含了两个选项:inProcess和outOfProcess
在inProcess的
Flavors
下,会定义XRT_FEATURE_SERVICE=OFF
在outOfProcess的
Flavors
下,会定义XRT_FEATURE_SERVICE=ON
仅在
outOfProcess
的Flavors
下会引用到:src:xrt:ipc:android
outOfProcessImplementation project(':src:xrt:ipc:android')
因此,如果只是编译inProcess
的模式,那么就不会包含src/xrt/ipc/android
目录下的相关代码了,这边以inProcess
为例进行分析。
auxiliary:android
auxiliary的翻译是辅助的,这个目录的gradle中并没有包含太多的信息,也没有包含CMakeLists的部分,因此只是一个纯android工程而已。
其中的具体作用以后再分析。
targets:android_common
这个模块的部分跟auxiliary:android
非常类似,在build.gradle
中也没有CMakeLists,也是一个普通的android library模块。
monado
根目录下的CMakeLists文件是整个monado runtime so的起始点,文件的部分有点长,一共有将近500行,逐段分析一下。
在分析之前需要记得一点,由于我们是通过gradle进行编译的inProcess
,在CMakeLists.txt之外有额外给出了一个参数:XRT_FEATURE_SERVICE=OFF
。
最早的60行大部分内容都是在定义环境变量,诸如指定CMake版本,C++版本
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657# Copyright 2018-2021, Collabora, Ltd.# SPDX-License-Identifier: BSL-1.0cmake_minimum_required(VERSION 3.10.2)project(XRT VERSION 21.0.0)# CMake 3.11 introduced CMP0072 - Prefer GLVNDif(POLICY CMP0072)cmake_policy(SET CMP0072 NEW)endif()option(XRT_OPENXR_INSTALL_ABSOLUTE_RUNTIME_PATH"Use the absolute path to the runtime in the installed manifest, rather than a bare filename."ON)option(XRT_OPENXR_INSTALL_ACTIVE_RUNTIME "Make Monado the default OpenXR runtime on install" ON)# We use C++17set(CMAKE_CXX_STANDARD 17)set(CMAKE_CXX_STANDARD_REQUIRED ON)# So that clangd/Intellisense/Sourcetrail know how to parse our code.set(CMAKE_EXPORT_COMPILE_COMMANDS ON)#### Dependencies###list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/sanitizers")include(CMakeDependentOption)include(SPIR-V)include(GNUInstallDirs)if(NOT GIT_DESC)include(GetGitRevisionDescription)git_describe(GIT_DESC "--always")endif()if(NOT ${CMAKE_VERSION} VERSION_LESS 3.9)include(CheckIPOSupported)check_ipo_supported(RESULT HAS_IPO)endif()# Android SDK doesn't look for 3.8 and 3.9, which is what new distros ship with.set(Python_ADDITIONAL_VERSIONS 3.8 3.9)if(NOT CMAKE_VERSION VERSION_LESS 3.12)find_package(Python3 REQUIRED Interpreter)set(PYTHON_EXECUTABLE Python3::Interpreter)else()find_program(PYTHON_EXECUTABLE python3)if(PYTHON_EXECUTABLE MATCHES "WindowsApps")# If you hit this error, you will have to install Python 3 or try harder to tell CMake where it is.message(FATAL_ERROR"Found WindowsApps alias for Python. Make sure Python3 is installed, then choose 'Manage App Execution Aliases' in Start and disable the aliases for Python.")endif()endif()第二个部分是一些项目中会使用到的依赖库
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109find_package(Eigen3 3 REQUIRED)find_package(Vulkan MODULE)find_package(EGL MODULE)find_package(HIDAPI MODULE)find_package(OpenHMD MODULE)find_package(OpenCVCOMPONENTScorecalib3dhighguiimgprocimgcodecsfeatures2dvideoCONFIG)find_package(Libusb1 MODULE)find_package(JPEG MODULE)find_package(realsense2 CONFIG)find_package(depthai CONFIG)find_package(SDL2 CONFIG)find_package(ZLIB MODULE)find_package(cJSON MODULE)find_package(Systemd MODULE)find_package(OpenGLES MODULE COMPONENTS V3)find_package(LeapV2 MODULE)find_package(ONNXRuntime MODULE)find_package(Percetto MODULE)if(NOT ANDROID)find_package(PkgConfig MODULE)endif()#https://github.com/arsenm/sanitizers-cmakefind_package(Sanitizers MODULE)add_library(xrt-pthreads INTERFACE)if(WIN32)find_package(pthreads_windows REQUIRED)target_link_libraries(xrt-pthreads INTERFACE PThreads4W::PThreads4W_CXXEXC)else()set(CMAKE_THREAD_PREFER_PTHREAD ON)find_package(Threads)target_link_libraries(xrt-pthreads INTERFACE Threads::Threads)endif()if(PKGCONFIG_FOUND AND NOT ANDROID)# @TODO Turn into a find_package LIBUVC file.pkg_check_modules(LIBUVC libuvc)# @TODO Turn into a find_package FFMPEG file.pkg_check_modules(FFMPEG libavcodec)endif()find_package(OpenGL)set(OPENGL_WITHOUT_GLX_FOUND ${OPENGL_FOUND})if(CMAKE_SYSTEM_NAME STREQUAL "Linux")set(XRT_HAVE_LINUX YES)# Compositor backendfind_package(X11)find_package(udev REQUIRED)set(XRT_HAVE_V4L2 TRUE)if(PKGCONFIG_FOUND)pkg_check_modules(XRANDR xrandr)pkg_check_modules(XCB xcb xcb-randr x11-xcb)pkg_search_module(WAYLAND wayland-client)pkg_search_module(WAYLAND_SCANNER wayland-scanner)pkg_search_module(WAYLAND_PROTOCOLS wayland-protocols)pkg_search_module(LIBDRM IMPORTED_TARGET libdrm)endif()find_package(OpenGL COMPONENTS GLX)pkg_search_module(DBUS dbus-1)pkg_search_module(LIBBSD libbsd)pkg_check_modules(GST gstreamer-1.0 gstreamer-app-1.0 gstreamer-video-1.0)pkg_check_modules(SURVIVE IMPORTED_TARGET survive)endif()find_library(RT_LIBRARY rt)if(ANDROID)find_library(ANDROID_LIBRARY android)find_library(ANDROID_LOG_LIBRARY log)endif()# Find a external SLAM implementationset(EXTERNAL_SLAM_SYSTEMS kimera_vio basalt)foreach(slam_system IN LISTS EXTERNAL_SLAM_SYSTEMS)if(PKGCONFIG_FOUND)pkg_check_modules(${slam_system} ${slam_system})endif()if(${slam_system}_FOUND)set(SLAM ON)set(SLAM_NAME ${slam_system})set(SLAM_LIBRARIES ${${slam_system}_LIBRARIES})set(SLAM_INCLUDE_DIRS ${${slam_system}_INCLUDE_DIRS})break()endif()endforeach()# ILLIXRset(ILLIXR_PATH""CACHE PATH "Path to ILLIXR headers")这里其实并没有什么重要的内容,但是要记住如果是
Android
工程,那么1234if(ANDROID)find_library(ANDROID_LIBRARY android)find_library(ANDROID_LOG_LIBRARY log)endif()我们是在Android Studio中进行编译的,其实IDE工具帮我们封装好了很多的事情,NDK的部分中有
build/cmake/android.toolchain.cmake
,其中line 2791234> # Standard cross-compiling stuff.> set(ANDROID TRUE)> set(CMAKE_SYSTEM_NAME Android)>第三部分就是一些预置option的打开和关闭了
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596option(XRT_FEATURE_COLOR_LOG "Enable logging in color on supported platforms" ON)cmake_dependent_option(XRT_HAVE_PERCETTO "Enable percetto support" ON "PERCETTO_FOUND" OFF)cmake_dependent_option(XRT_FEATURE_TRACING "Enable debug tracing on supported platforms" OFF "XRT_HAVE_PERCETTO" OFF)cmake_dependent_option(CMAKE_INTERPROCEDURAL_OPTIMIZATION "Enable inter-procedural (link-time) optimization" OFF "HAS_IPO" OFF)cmake_dependent_option(XRT_HAVE_WAYLAND "Enable Wayland support" ON "WAYLAND_FOUND AND WAYLAND_SCANNER_FOUND AND WAYLAND_PROTOCOLS_FOUND AND LIBDRM_FOUND" OFF)cmake_dependent_option(XRT_HAVE_WAYLAND_DIRECT "Enable Wayland direct support" ON "XRT_HAVE_WAYLAND AND LIBDRM_FOUND AND WAYLAND_PROTOCOLS_VERSION VERSION_GREATER_EQUAL 1.22" OFF)cmake_dependent_option(XRT_HAVE_XLIB "Enable xlib support" ON "X11_FOUND" OFF)cmake_dependent_option(XRT_HAVE_XRANDR "Enable xlib-xrandr support" ON "XRANDR_FOUND" OFF)cmake_dependent_option(XRT_HAVE_XCB "Enable xcb support" ON "XCB_FOUND" OFF)cmake_dependent_option(XRT_HAVE_VULKAN "Enable Vulkan Graphics API support (also needed for compositor)" ON "VULKAN_FOUND" OFF)cmake_dependent_option(XRT_HAVE_OPENGL "Enable OpenGL Graphics API support" ON "OPENGL_WITHOUT_GLX_FOUND" OFF)cmake_dependent_option(XRT_HAVE_OPENGL_GLX "Enable OpenGL Graphics API support on X11 (GLX)" ON "XRT_HAVE_OPENGL; OpenGL_GLX_FOUND" OFF)cmake_dependent_option(XRT_HAVE_OPENGLES "Enable OpenGL-ES Graphics API support" ON "OpenGLES_FOUND" OFF)cmake_dependent_option(XRT_HAVE_EGL "Enable OpenGL(-ES) on EGL Graphics API support" ON "EGL_FOUND; XRT_HAVE_OPENGL OR XRT_HAVE_OPENGLES" OFF)cmake_dependent_option(XRT_HAVE_DBUS "Enable dbus support (for BLE support)" ON "DBUS_FOUND" OFF)cmake_dependent_option(XRT_FEATURE_COMPOSITOR_MAIN "Build main compositor host functionality" ON "XRT_HAVE_VULKAN; XRT_HAVE_WAYLAND OR XRT_HAVE_XCB OR ANDROID OR WIN32" OFF)cmake_dependent_option(XRT_HAVE_LIBBSD "Enable libbsd support" ON "LIBBSD_FOUND" OFF)cmake_dependent_option(XRT_FEATURE_OPENXR "Build OpenXR runtime target" ON "XRT_FEATURE_COMPOSITOR_MAIN" OFF)cmake_dependent_option(XRT_FEATURE_IPC "Enable the build of the IPC layer" ON "NOT WIN32" OFF)cmake_dependent_option(XRT_FEATURE_SERVICE "Enable separate service module for OpenXR runtime" ON "XRT_FEATURE_IPC AND XRT_FEATURE_OPENXR" OFF)cmake_dependent_option(XRT_HAVE_SYSTEMD "Enable systemd support (for socket activation of service)" ON "Systemd_FOUND AND XRT_FEATURE_SERVICE" OFF)cmake_dependent_option(XRT_INSTALL_SYSTEMD_UNIT_FILES "Install user unit files for systemd socket activation on installation" ON "XRT_HAVE_SYSTEMD" OFF)cmake_dependent_option(XRT_INSTALL_ABSOLUTE_SYSTEMD_UNIT_FILES "Use an absolute path to monado-system in installed user unit files for systemd socket activation" ON "XRT_INSTALL_SYSTEMD_UNIT_FILES" OFF)cmake_dependent_option(XRT_FEATURE_STEAMVR_PLUGIN "Build SteamVR plugin" ON "NOT ANDROID" OFF)if(NOT DEFINED XRT_FEATURE_OPENXR_LAYER_DEPTH)set(XRT_FEATURE_OPENXR_LAYER_DEPTH ON)endif()if(NOT DEFINED XRT_FEATURE_OPENXR_LAYER_CUBE)set(XRT_FEATURE_OPENXR_LAYER_CUBE OFF)endif()if(NOT DEFINED XRT_FEATURE_OPENXR_LAYER_CYLINDER)set(XRT_FEATURE_OPENXR_LAYER_CYLINDER ON)endif()if(NOT DEFINED XRT_FEATURE_OPENXR_LAYER_EQUIRECT2)set(XRT_FEATURE_OPENXR_LAYER_EQUIRECT2 ON)endif()if(NOT DEFINED XRT_FEATURE_OPENXR_LAYER_EQUIRECT1)set(XRT_FEATURE_OPENXR_LAYER_EQUIRECT1 ON)endif()# Most users won't touch these.mark_as_advanced(XRT_FEATURE_COMPOSITOR_MAIN XRT_FEATURE_OPENXR)if(CMAKE_SYSTEM_NAME STREQUAL "Linux")set(XRT_HAVE_LIBUDEV ON)set(XRT_HAVE_INTERNAL_HID ON)else()cmake_dependent_option(XRT_HAVE_LIBUDEV "Enable libudev (used for device probing on Linux)" ON "UDEV_FOUND" OFF)endif()cmake_dependent_option(XRT_HAVE_LIBUSB "Enable libusb (used for most drivers)" ON "LIBUSB1_FOUND" OFF)cmake_dependent_option(XRT_HAVE_JPEG "Enable jpeg code (used for some video drivers)" ON "JPEG_FOUND" OFF)cmake_dependent_option(XRT_HAVE_OPENCV "Enable OpenCV backend" ON "OpenCV_FOUND" OFF)cmake_dependent_option(XRT_HAVE_LIBUVC "Enable libuvc video driver" ON "LIBUVC_FOUND AND XRT_HAVE_LIBUSB" OFF)cmake_dependent_option(XRT_HAVE_FFMPEG "Enable ffmpeg testing video driver" ON "FFMPEG_FOUND" OFF)cmake_dependent_option(XRT_HAVE_SDL2 "Enable use of SDL2" ON "SDL2_FOUND AND XRT_HAVE_OPENGL" OFF)cmake_dependent_option(XRT_HAVE_SYSTEM_CJSON "Enable cJSON from system, instead of bundled source" ON "CJSON_FOUND" OFF)cmake_dependent_option(XRT_HAVE_GST "Enable gstreamer" ON "GST_FOUND" OFF)cmake_dependent_option(XRT_HAVE_REALSENSE "Enable RealSense support" ON "realsense2_FOUND" OFF)cmake_dependent_option(XRT_HAVE_ONNXRUNTIME "Enable ONNX runtime support" ON "ONNXRUNTIME_FOUND" OFF)cmake_dependent_option(XRT_HAVE_KIMERA_SLAM "Enable Kimera support" ON "kimera_vio_FOUND" OFF)cmake_dependent_option(XRT_HAVE_BASALT_SLAM "Enable Basalt support" ON "basalt_FOUND" OFF)cmake_dependent_option(XRT_HAVE_SLAM "Enable SLAM tracking support" ON "SLAM;XRT_HAVE_OPENCV" OFF)cmake_dependent_option(XRT_BUILD_DRIVER_PSVR "Enable PSVR HMD driver" ON "HIDAPI_FOUND" OFF)cmake_dependent_option(XRT_BUILD_DRIVER_REALSENSE "Enable RealSense device driver" ON "XRT_HAVE_REALSENSE" OFF)cmake_dependent_option(XRT_BUILD_DRIVER_VIVE "Enable driver for HTC Vive, Vive Pro, Valve Index, and their controllers" ON "ZLIB_FOUND AND XRT_HAVE_LINUX" OFF)cmake_dependent_option(XRT_BUILD_DRIVER_OHMD "Enable OpenHMD driver" ON "OPENHMD_FOUND" OFF)cmake_dependent_option(XRT_BUILD_DRIVER_HANDTRACKING "Enable Camera Hand Tracking driver" ON "XRT_HAVE_ONNXRUNTIME AND XRT_HAVE_OPENCV AND XRT_HAVE_V4L2" OFF)cmake_dependent_option(XRT_BUILD_DRIVER_DAYDREAM "Enable the Google Daydream View controller driver (BLE, via D-Bus)" ON "XRT_HAVE_DBUS" OFF)cmake_dependent_option(XRT_BUILD_DRIVER_ARDUINO "Enable Arduino input device with BLE via via D-Bus" ON "XRT_HAVE_DBUS" OFF)cmake_dependent_option(XRT_BUILD_DRIVER_ILLIXR "Enable ILLIXR driver" ON "ILLIXR_PATH" OFF)option(XRT_BUILD_DRIVER_DUMMY "Enable dummy driver" ON)cmake_dependent_option(XRT_BUILD_DRIVER_ULV2 "Enable Ultraleap v2 driver" ON "LeapV2_FOUND" OFF)cmake_dependent_option(XRT_BUILD_DRIVER_REMOTE "Enable remote debugging driver" ON "XRT_HAVE_LINUX OR ANDROID" OFF)cmake_dependent_option(XRT_BUILD_DRIVER_WMR "Enable Windows Mixed Reality driver" ON "NOT WIN32" OFF)option(XRT_BUILD_SAMPLES "Enable compiling sample code implementations that will not be linked into any final targets" ON)# These all use the Monado internal hid wrapper.cmake_dependent_option(XRT_BUILD_DRIVER_HDK "Enable HDK driver" ON "XRT_HAVE_INTERNAL_HID" OFF)cmake_dependent_option(XRT_BUILD_DRIVER_PSMV "Enable Playstation Move driver" ON "XRT_HAVE_INTERNAL_HID" OFF)cmake_dependent_option(XRT_BUILD_DRIVER_HYDRA "Enable Hydra driver" ON "XRT_HAVE_INTERNAL_HID" OFF)cmake_dependent_option(XRT_BUILD_DRIVER_NS "Enable North Star driver" ON "XRT_HAVE_INTERNAL_HID" OFF)cmake_dependent_option(XRT_BUILD_DRIVER_VF "Build video frame driver (for video file support, uses gstreamer)" ON "XRT_HAVE_GST" OFF)cmake_dependent_option(XRT_BUILD_DRIVER_DEPTHAI "DepthAI" ON "depthai_FOUND" OFF)cmake_dependent_option(XRT_BUILD_DRIVER_SURVIVE "Enable libsurvive driver" ON "SURVIVE_FOUND" OFF)cmake_dependent_option(XRT_BUILD_DRIVER_ANDROID "Enable Android sensors driver" ON "ANDROID" OFF)cmake_dependent_option(XRT_BUILD_DRIVER_QWERTY "Enable Qwerty driver" ON "XRT_HAVE_SDL2" OFF)cmake_dependent_option(XRT_BUILD_DRIVER_EUROC "Enable EuRoC dataset driver for SLAM evaluation" ON "XRT_HAVE_OPENCV" OFF)表达式
cmake_dependent_option
的含义是:cmake_dependent_option(OPT_VAR "OPT_VAR_DES" DEF_VAL_1 "CONDITION_EXP" DEF_VAR_2)
其中
OPT_VAR
的值会取决于"CONDITION_EXP"
,如果这个值为True
,那么OPT_VAR
的值就是DEF_VAL_1
,如果为False
,那就是DEF_VAR_2
其中的变量推导和计算我们就忽略了,直接最后的message输出:src/xrt/targets/openxr_android/.cxx/cmake/inProcessDebug/x86_64/cmake_server_log.txt
这个输出的部分其实是第五部分的内容。
|
|
第四部分是真正项目编译有关的了,其中定义
XRT_ANDROID_PACKAGE
,可以看出是根据我们的Flavor来的123456789101112131415161718if(ANDROID AND NOT XRT_ANDROID_PACKAGE)if(XRT_FEATURE_SERVICE)set(XRT_ANDROID_PACKAGE "org.freedesktop.monado.openxr_runtime.out_of_process")else()set(XRT_ANDROID_PACKAGE "org.freedesktop.monado.openxr_runtime.in_process")endif()endif()if(ANDROID)set(VK_USE_PLATFORM_ANDROID_KHR TRUE)endif()#### Descend into the source###add_subdirectory(src)add_subdirectory(doc)最后它留了一个伏笔,
add_subdirectory(src)
因此,整个根目录下的CMakeList其实是完成了大部分的宏定义,并且引出了整个编译的subdirectory,也即src目录
src
其中monado/src/CMakeLists.txt
的内容
|
|
src/external
monado/src/external/CMakeLists.txt
中大部分都是add_library
,按照顺序依次分析
Catch2
123456# Copyright 2020, Collabora, Ltd.# SPDX-License-Identifier: BSL-1.0# Catch2add_library(xrt-external-catch2 INTERFACE)target_include_directories(xrt-external-catch2 INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/Catch2)openvr
1234add_library(xrt-external-openvr INTERFACE)target_include_directories(xrt-external-openvr INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/openvr_includes)cJSON:
XRT_HAVE_SYSTEM_CJSON:OFF
12345678# cJSONadd_library(xrt-external-cjson INTERFACE)if(XRT_HAVE_SYSTEM_CJSON)target_link_libraries(xrt-external-cjson INTERFACE cJSON::cJSON)else()target_include_directories(xrt-external-cjson INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/cjson)target_compile_definitions(xrt-external-cjson INTERFACE CJSON_HIDE_SYMBOLS)endif()FlexKalman
123# FlexKalmanadd_library(xrt-external-flexkalman INTERFACE)target_include_directories(xrt-external-flexkalman INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/flexkalman)Glad
123# Gladadd_library(xrt-external-glad INTERFACE)target_include_directories(xrt-external-glad INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/glad/include)Hungarian graph algorithm
123# Hungarian graph algorithmadd_library(xrt-external-hungarian INTERFACE)target_include_directories(xrt-external-hungarian INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/hungarian)JNIPP and Android JNI wrappers
123456789101112# JNIPP and Android JNI wrappersif(ANDROID)add_library(xrt-external-jnipp STATIC jnipp/jnipp.cpp)target_include_directories(xrt-external-jnipp PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/jnipp)file(GLOB WRAP_SOURCES android-jni-wrap/wrap/*.cpp)add_library(xrt-external-jni-wrap STATIC ${WRAP_SOURCES})target_include_directories(xrt-external-jni-wrap PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/android-jni-wrap)target_link_libraries(xrt-external-jni-wrap PUBLIC xrt-external-jnipp)endif()OpenXR
12345# OpenXRadd_library(xrt-external-openxr INTERFACE)target_include_directories(xrt-external-openxr INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/openxr_includes)External SLAM tracking:
cmake_dependent_option(XRT_HAVE_SLAM "Enable SLAM tracking support" ON "SLAM;XRT_HAVE_OPENCV" OFF)
- 因为
XRT_HAVE_SLAM = OFF
,从而我们推导出SLAM=OFF
12345678910# External SLAM trackingif(SLAM)add_library(xrt-external-slam STATIC slam_tracker/slam_tracker.hpp)set_target_properties(xrt-external-slam PROPERTIES LINKER_LANGUAGE CXX)target_include_directories(xrt-external-slam INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/slam_tracker)target_include_directories(xrt-external-slam INTERFACE ${SLAM_INCLUDE_DIRS})target_link_libraries(xrt-external-slam INTERFACE ${SLAM_LIBRARIES})endif()STB
123# STBadd_library(xrt-external-stb INTERFACE)target_include_directories(xrt-external-stb INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/stb)imgui:
XRT_HAVE_OPENGL:OFF
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758# imguiif(XRT_HAVE_OPENGL)add_library(xrt-external-imgui STATICimgui/imgui/cimgui.cppimgui/imgui/cimgui.himgui/imgui/cimplot.cppimgui/imgui/cimplot.himgui/imgui/imconfig.himgui/imgui/imgui.cppimgui/imgui/imgui.himgui/imgui/imgui_demo.cppimgui/imgui/imgui_draw.cppimgui/imgui/imgui_impl_opengl3.cppimgui/imgui/imgui_impl_opengl3.himgui/imgui/imgui_internal.himgui/imgui/imgui_widgets.cppimgui/imgui/implot.cppimgui/imgui/implot.himgui/imgui/implot_demo.cppimgui/imgui/implot_internal.himgui/imgui/implot_items.cppimgui/imgui/imstb_rectpack.himgui/imgui/imstb_textedit.himgui/imgui/imstb_truetype.himgui/imgui_monado/imgui_monado.cpp)target_include_directories(xrt-external-imgui SYSTEM PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/imgui)target_include_directories(xrt-external-imgui PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/imgui)target_compile_definitions(xrt-external-imgui PUBLIC CIMGUI_NO_EXPORT)set_target_properties(xrt-external-imgui PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF)target_link_libraries(xrt-external-imgui PUBLIC xrt-external-glad)if(XRT_HAVE_SDL2)add_library(xrt-external-imgui-sdl2 STATICimgui/imgui/cimgui_sdl.cpp imgui/imgui/imgui_impl_sdl.cppimgui/imgui/imgui_impl_sdl.h)target_link_libraries(xrt-external-imgui-sdl2PUBLIC xrt-external-imguiPUBLIC ${SDL2_LIBRARIES})target_include_directories(xrt-external-imgui-sdl2 PUBLIC ${SDL2_INCLUDE_DIRS})target_include_directories(xrt-external-imgui-sdl2 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/imgui)set_target_properties(xrt-external-imgui-sdl2 PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF)endif()endif()
在这里需要注意的是,真正参与编译的library中,只有JNIPP and Android JNI wrappers
是使用的STATIC
关键字:
add_library(xrt-external-jnipp STATIC jnipp/jnipp.cpp)
add_library(xrt-external-jni-wrap STATIC ${WRAP_SOURCES})
这两个库最终都会被link到xrt-external-jni-wrap
:
target_link_libraries(xrt-external-jni-wrap PUBLIC xrt-external-jnipp)
其余的模块都是使用的INTERFACE
关键字:
add_library(xrt-external-catch2 INTERFACE)
add_library(xrt-external-catch2 INTERFACE)
add_library(xrt-external-openvr INTERFACE)
add_library(xrt-external-cjson INTERFACE)
add_library(xrt-external-flexkalman INTERFACE)
add_library(xrt-external-glad INTERFACE)
add_library(xrt-external-hungarian INTERFACE)
add_library(xrt-external-openxr INTERFACE)
add_library(xrt-external-stb INTERFACE)
以上是整个extrnal模块的分析,可以看出来实质上是编译了android jni的wrap库。
src/xrt
重要的部分其实是在monado/src/xrt/CMakeLists.txt
,其中:XRT_FEATURE_IPC:ON
|
|
这个部分只能挨个来拆解看一下。
include
monado/src/xrt/include/CMakeLists.txt
|
|
xrt
monado/src/xrt/include/xrt/CMakeLists.txt
,这个cmake依旧做了一个INTERFACE
的library,再看一下include/xrt/CMakeLists.txt
的内容
|
|
根据我们先前的解析和定义,其中以XRT_BUILD_DRIVER_
开头的driver定义为ON的:
XRT_BUILD_DRIVER_ANDROID:ON
XRT_BUILD_DRIVER_DUMMY:ON
XRT_BUILD_DRIVER_REMOTE:ON
XRT_BUILD_DRIVER_WMR:ON
因此,这个模块其实就是定义了四个宏:
#define XRT_BUILD_DRIVER_ANDROID
#define XRT_BUILD_DRIVER_DUMMY
#define XRT_BUILD_DRIVER_REMOTE
#define XRT_BUILD_DRIVER_WMR
接着看include/xrt/CMakeLists.txt
的第二部分configure_file
,这个部分其实是做文件的copy,并把其中的一些变量做一下替换,简单来看看两个文件。
./src/xrt/include/xrt/xrt_config_android.h.cmake_in
123456789101112// Copyright 2020, Collabora, Ltd.// SPDX-License-Identifier: BSL-1.0/*!* @file* @brief Android defines.* @author Ryan Pavlik <ryan.pavlik@collabora.com>* @ingroup xrt_iface*/生成文件
src/xrt/targets/openxr_android/.cxx/cmake/inProcessDebug/arm64-v8a/src/xrt/include/xrt/xrt_config_android.h
123456789101112// Copyright 2020, Collabora, Ltd.// SPDX-License-Identifier: BSL-1.0/*!* @file* @brief Android defines.* @author Ryan Pavlik <ryan.pavlik@collabora.com>* @ingroup xrt_iface*/
./src/xrt/include/xrt/xrt_config_drivers.h.cmake_in
123456789101112// Copyright 2019-2020, Collabora, Ltd.// SPDX-License-Identifier: BSL-1.0/*!* @file* @brief What drivers are we building.* @author Jakob Bornecrantz <jakob@collabora.com>* @ingroup xrt_iface*/@FILE_CONTENTS@生成文件
src/xrt/targets/openxr_android/.cxx/cmake/inProcessDebug/arm64-v8a/src/xrt/include/xrt/xrt_config_drivers.h
123456789101112131415// Copyright 2019-2020, Collabora, Ltd.// SPDX-License-Identifier: BSL-1.0/*!* @file* @brief What drivers are we building.* @author Jakob Bornecrantz <jakob@collabora.com>* @ingroup xrt_iface*/@FILE_CONTENTS@,其实在
include/src/CMakeLists.txt
中的for循环中有定义了1234567> set(FILE_CONTENTS "")> foreach(driver ${AVAILABLE_DRIVERS})> if(XRT_BUILD_DRIVER_${driver})> string(APPEND FILE_CONTENTS "#define XRT_BUILD_DRIVER_${driver}\n")> endif()> endforeach()>
auxiliary
monado/src/xrt/auxiliary/CMakeLists.txt
,这个CMakeLists的部分有点长,拆开来分析一下
首先是又增加了一个目录引用:
add_subdirectory(bindings)
1234# Copyright 2019-2021, Collabora, Ltd.# SPDX-License-Identifier: BSL-1.0add_subdirectory(bindings)
bindings
monado/src/xrt/auxiliary/bindings/CMakeLists.txt
|
|
- 通过阅读
src/xrt/auxiliary/bindings/bindings.json
可以知道,这一段其实是通过json文件生成c语言级别的解析函数。
回到monado/src/xrt/auxiliary/CMakeLists.txt
Common includes
123456# Common includesadd_library(aux-includes INTERFACE)target_include_directories(aux-includes INTERFACE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})target_link_libraries(aux-includes INTERFACE xrt-interfaces)OpenGL library:
XRT_HAVE_OPENGLES:ON
,XRT_HAVE_EGL:ON
123456789101112131415161718# OpenGL library.if(XRT_HAVE_OPENGL OR XRT_HAVE_OPENGLES)add_library(aux_ogl STATICogl/ogl_documentation.hogl/ogl_api.cogl/ogl_api.hogl/ogl_helpers.cogl/ogl_helpers.h)target_link_libraries(aux_ogl PUBLIC aux-includes xrt-external-glad)if(XRT_HAVE_EGL)target_sources(aux_ogl PRIVATE ogl/egl_api.c ogl/egl_api.h)endif()if(XRT_HAVE_OPENGLES)target_link_libraries(aux_ogl PUBLIC EGL::EGL)endif()endif()Math library
123456789101112131415161718192021222324252627282930# Math library.add_library(aux_math STATICmath/m_api.hmath/m_base.cppmath/m_eigen_interop.hppmath/m_filter_fifo.cmath/m_filter_fifo.hmath/m_filter_one_euro.cmath/m_filter_one_euro.hmath/m_hash.cppmath/m_imu_3dof.cmath/m_imu_3dof.hmath/m_imu_pre.cmath/m_imu_pre.hmath/m_optics.cmath/m_permutation.cmath/m_permutation.hmath/m_predict.cmath/m_predict.hmath/m_quatexpmap.cppmath/m_relation_history.hmath/m_relation_history.cppmath/m_space.cppmath/m_space.hmath/m_vec2.hmath/m_vec3.h)target_link_libraries(aux_math PUBLIC aux-includes aux_util)target_include_directories(aux_math SYSTEM PRIVATE ${EIGEN3_INCLUDE_DIR})OS library:
XRT_HAVE_DBUS:OFF
123456789101112131415# OS library.add_library(aux_os STATICos/os_ble.hos/os_documentation.hos/os_hid.hos/os_hid_hidraw.cos/os_threading.h)target_link_libraries(aux_os PUBLIC aux-includes xrt-pthreads)if(XRT_HAVE_DBUS)target_sources(aux_os PRIVATE os/os_ble_dbus.c)target_link_libraries(aux_os PRIVATE ${DBUS_LIBRARIES})target_include_directories(aux_os SYSTEM PRIVATE ${DBUS_INCLUDE_DIRS})endif()GStreamer library:
XRT_HAVE_GST:OFF
1234567891011121314# GStreamer library.if(XRT_HAVE_GST)add_library(aux_gstreamer STATICgstreamer/gst_internal.hgstreamer/gst_sink.hgstreamer/gst_sink.cgstreamer/gst_pipeline.hgstreamer/gst_pipeline.c)target_link_libraries(aux_gstreamer PUBLIC aux-includes)target_link_libraries(aux_gstreamer PRIVATE xrt-interfaces aux_math aux_os ${GST_LIBRARIES})target_include_directories(aux_gstreamer PRIVATE ${GST_INCLUDE_DIRS})endif()Tracking library
1234567891011121314151617# Tracking library.add_library(aux_tracking STATICtracking/t_data_utils.ctracking/t_imu_fusion.hpptracking/t_imu.cpptracking/t_imu.htracking/t_lowpass_vector.hpptracking/t_lowpass.hpptracking/t_tracking.h)target_link_libraries(aux_trackingPUBLIC aux-includes xrt-external-cjsonPRIVATE aux_math aux_util xrt-external-flexkalman xrt-external-hungarian)target_include_directories(aux_tracking SYSTEM PRIVATE ${EIGEN3_INCLUDE_DIR})OpenCV,
XRT_HAVE_OPENCV:OFF
12345678910111213141516171819202122232425262728if(XRT_HAVE_OPENCV)target_sources(aux_trackingPRIVATEtracking/t_calibration_opencv.hpptracking/t_calibration.cpptracking/t_convert.cpptracking/t_debug_hsv_filter.cpptracking/t_debug_hsv_picker.cpptracking/t_debug_hsv_viewer.cpptracking/t_euroc_recorder.cpptracking/t_euroc_recorder.htracking/t_file.cpptracking/t_frame_cv_mat_wrapper.cpptracking/t_frame_cv_mat_wrapper.hpptracking/t_fusion.hpptracking/t_helper_debug_sink.hpptracking/t_hsv_filter.ctracking/t_kalman.cpptracking/t_tracker_psmv_fusion.hpptracking/t_tracker_psmv.cpptracking/t_tracker_psvr.cpptracking/t_tracker_hand.cpp)target_include_directories(aux_tracking SYSTEM PRIVATE ${OpenCV_INCLUDE_DIRS})target_link_libraries(aux_tracking PUBLIC ${OpenCV_LIBRARIES})endif()SLAM,
XRT_HAVE_SLAM:OFF
1234if(XRT_HAVE_SLAM)target_sources(aux_tracking PRIVATE tracking/t_tracker_slam.cpp)target_link_libraries(aux_tracking PRIVATE xrt-external-slam)endif()Util library
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071# Util library.add_library(aux_util STATICutil/u_bitwise.cutil/u_bitwise.hutil/u_debug.cutil/u_debug.hutil/u_device.cutil/u_device.hutil/u_distortion.cutil/u_distortion.hutil/u_distortion_mesh.cutil/u_distortion_mesh.hutil/u_documentation.hutil/u_file.cutil/u_file.cpputil/u_file.hutil/u_format.cutil/u_format.hutil/u_frame.cutil/u_frame.hutil/u_generic_callbacks.hpputil/u_git_tag.hutil/u_hand_tracking.cutil/u_hand_tracking.hutil/u_handles.cutil/u_handles.hutil/u_hashmap.cpputil/u_hashmap.hutil/u_hashset.cpputil/u_hashset.hutil/u_json.cutil/u_json.hutil/u_json.hpputil/u_logging.cutil/u_logging.hutil/u_misc.cutil/u_misc.hutil/u_pacing.hutil/u_pacing_app.cutil/u_pacing_compositor.cutil/u_pacing_compositor_fake.cutil/u_sink.hutil/u_sink_combiner.cutil/u_sink_converter.cutil/u_sink_deinterleaver.cutil/u_sink_queue.cutil/u_sink_quirk.cutil/u_sink_split.cutil/u_string_list.cpputil/u_string_list.hutil/u_string_list.hpputil/u_template_historybuf.hpputil/u_time.cpputil/u_time.hutil/u_trace_marker.cutil/u_trace_marker.hutil/u_var.cpputil/u_var.hutil/u_config_json.cutil/u_config_json.hutil/u_verify.hutil/u_process.cutil/u_process.h"${CMAKE_CURRENT_BINARY_DIR}/u_git_tag.c")configure_file("${CMAKE_CURRENT_SOURCE_DIR}/util/u_git_tag.c.in" "${CMAKE_CURRENT_BINARY_DIR}/u_git_tag.c"@ONLY)target_link_libraries(aux_util PUBLIC aux-includes xrt-pthreads aux_generated_bindings aux_math)XRT_HAVE_JPEG:OFF
1234if(XRT_HAVE_JPEG)target_link_libraries(aux_util PRIVATE ${JPEG_LIBRARIES})target_include_directories(aux_util PRIVATE ${JPEG_INCLUDE_DIRS})endif()XRT_HAVE_SYSTEM_CJSON:OFF
123456if(XRT_HAVE_SYSTEM_CJSON)target_link_libraries(aux_util PUBLIC cJSON::cJSON)target_compile_definitions(aux_util PRIVATE XRT_HAVE_SYSTEM_CJSON)else()target_link_libraries(aux_util PUBLIC xrt-external-cjson)endif()XRT_FEATURE_TRACING:OFF
,XRT_HAVE_PERCETTO:OFF
123if(XRT_FEATURE_TRACING AND XRT_HAVE_PERCETTO)target_link_libraries(aux_util PUBLIC Percetto::percetto)endif()XRT_HAVE_LIBBSD:OFF
1234if(XRT_HAVE_LIBBSD)target_include_directories(aux_util SYSTEM PRIVATE ${LIBBSD_INCLUDE_DIRS})target_link_libraries(aux_util PUBLIC ${LIBBSD_LIBRARIES})endif()ANDROID:ON
123if(ANDROID)target_link_libraries(aux_util PUBLIC ${ANDROID_LOG_LIBRARY})endif()Vulkan library,
XRT_HAVE_VULKAN:ON
,ANDROID=ON
12345678910111213141516171819if(XRT_HAVE_VULKAN)# Vulkan library.add_library(aux_vk STATICvk/vk_command_buffer.cvk/vk_documentation.hvk/vk_helpers.cvk/vk_helpers.hvk/vk_image_allocator.cvk/vk_image_allocator.hvk/vk_state_creators.c)target_link_libraries(aux_vk PUBLIC aux_os aux_util)target_link_libraries(aux_vk PUBLIC Vulkan::Vulkan)target_include_directories(aux_vk PUBLIC ${Vulkan_INCLUDE_DIR})if(ANDROID)target_link_libraries(aux_vk PUBLIC ${ANDROID_LIBRARY})endif()endif()ViVE/SURVIVE Drivers,
XRT_BUILD_DRIVER_VIVE:OFF
,XRT_BUILD_DRIVER_SURVIVE:OFF
123456789101112131415if(XRT_BUILD_DRIVER_VIVE OR XRT_BUILD_DRIVER_SURVIVE)set(VIVE_CONFIG_SOURCE_FILES vive/vive_config.h vive/vive_config.c)add_library(aux_vive STATIC ${VIVE_CONFIG_SOURCE_FILES})target_link_libraries(aux_vivePRIVATExrt-interfacesaux_utilaux_mathaux_trackingxrt-external-cjson${ZLIB_LIBRARIES})target_include_directories(aux_vive PRIVATE ${ZLIB_INCLUDE_DIRS})endif()aux_vk,aux_android
123456789101112131415161718192021222324252627282930313233343536373839if(ANDROID)add_library(android_app_glue STATIC${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c)target_include_directories(android_app_glue PUBLIC ${ANDROID_NDK}/sources/android/native_app_glue)# disable these warnings in external codetarget_compile_options(android_app_glue PRIVATE -Wno-format-pedantic)add_library(aux_android STATICandroid/android_ahardwarebuffer_allocator.candroid/android_ahardwarebuffer_allocator.handroid/android_custom_surface.cppandroid/android_custom_surface.handroid/android_globals.cppandroid/android_globals.handroid/android_load_class.cppandroid/android_load_class.hppandroid/android_looper.cppandroid/android_looper.handroid/org.freedesktop.monado.auxiliary.cppandroid/org.freedesktop.monado.auxiliary.hppandroid/org.freedesktop.monado.auxiliary.impl.hpp)target_link_libraries(aux_androidPUBLIC aux_utilPRIVATE${ANDROID_LIBRARY}${ANDROID_LOG_LIBRARY}xrt-external-jni-wrapxrt-external-jnippandroid_app_glue)target_link_libraries(aux_vk PUBLIC aux_android)endif()
整个编译的CMakeLists非常长,但是其中真正编译出来的部分其实是
add_library(aux_ogl STATIC XXXX)
add_library(aux_math STATIC XXXX)
add_library(aux_tracking STATIC XXXX)
add_library(aux_util STATIC XXXX)
add_library(aux_vk STATIC XXXX)
add_library(android_app_glue STATIC XXXX)
add_library(aux_android STATIC XXXX)
小结:从这里现在还无法判断出有哪些最终的target,但是从auxiliary的定义来说,是辅助工具类,所以这里大部分的target其实给其他模块做link使用的,这个可以在后面的CMakeList.txt中看到
drivers
monado/src/xrt/drivers/CMakeLists.txt
,drivers的部分依旧非常长,由最早monado/CMakeLists.txt
中的定义,我们可知:
XRT_BUILD_DRIVER_ARDUINO
XRT_BUILD_DRIVER_DAYDREAM
XRT_BUILD_DRIVER_DEPTHAI
XRT_BUILD_DRIVER_QWERTY
XRT_BUILD_DRIVER_HDK
XRT_BUILD_DRIVER_HYDRA
XRT_BUILD_DRIVER_NS
XRT_BUILD_DRIVER_ULV2
XRT_BUILD_DRIVER_OHMD
XRT_BUILD_DRIVER_PSMV
XRT_BUILD_DRIVER_PSVR
XRT_BUILD_DRIVER_REALSENSE
XRT_BUILD_DRIVER_VIVE
XRT_HAVE_V4L2
XRT_BUILD_DRIVER_VF
XRT_BUILD_DRIVER_HANDTRACKING
XRT_BUILD_DRIVER_SURVIVE
XRT_BUILD_DRIVER_ILLIXR
XRT_BUILD_DRIVER_EUROC
都是OFF
的状态,所以整个CMakeLists.txt被简化为:
|
|
由此可知,这边参与编译的有:
add_library(drv_dummy STATIC XXXX)
add_library(drv_remote STATIC XXXX)
add_library(drv_android STATIC XXXX)
add_library(drv_multi STATIC XXXX)
add_library(drv_wmr STATIC XXXX)
add_library(drv_sample STATIC XXXX)
变量ENABLED_HEADSET_DRIVERS
,ENABLED_DRIVERS
的值分别为
ENABLED_HEADSET_DRIVERS = dummy remote drv_multi wmr
ENABLED_DRIVERS = android
小结:这样的话也比较容易理解,整个drivers目录其实就是针对不同的driver模块做了实现,具体的需要到各个module中去看。
compositor
monado/src/xrt/compositor/CMakeLists.txt
,compositor是整个monado runtime中比较重要的模块,拆解分析:
library :
comp_client
123456789101112131415# Copyright 2019-2021, Collabora, Ltd.# SPDX-License-Identifier: BSL-1.0#### Client library#add_library(comp_client STATIC)target_link_libraries(comp_clientPUBLIC xrt-interfacesPRIVATE aux_util)target_include_directories(comp_client PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})link vulkan,
XRT_HAVE_VULKAN:ON
1234567if(XRT_HAVE_VULKAN)target_sources(comp_client PRIVATE client/comp_vk_client.c client/comp_vk_client.hclient/comp_vk_glue.c)target_link_libraries(comp_client PRIVATE aux_vk)endif()link open gles
XRT_HAVE_OPENGLES:ON
XRT_HAVE_OPENGL:OFF
XRT_HAVE_EGL:ON
XRT_HAVE_OPENGL_GLX:OFF
XRT_HAVE_XLIB:OFF
1234567891011121314151617181920212223242526272829303132333435if(XRT_HAVE_OPENGL OR XRT_HAVE_OPENGLES)target_sources(comp_clientPRIVATE client/comp_gl_client.c client/comp_gl_client.hclient/comp_gl_memobj_swapchain.c client/comp_gl_memobj_swapchain.h)target_link_libraries(comp_client PRIVATE aux_ogl)endif()if(XRT_HAVE_OPENGL)target_sources(comp_client PRIVATE client/comp_gl_glue.c)endif()if(XRT_HAVE_OPENGLES)target_sources(comp_client PRIVATE client/comp_gles_glue.c)endif()if(XRT_HAVE_EGL)target_sources(comp_client PRIVATE client/comp_gl_eglimage_swapchain.cclient/comp_gl_eglimage_swapchain.h)endif()if(XRT_HAVE_OPENGL_GLX AND XRT_HAVE_XLIB)target_sources(comp_client PRIVATE client/comp_gl_xlib_client.c client/comp_gl_xlib_client.hclient/comp_gl_xlib_glue.c)target_link_libraries(comp_client PRIVATE OpenGL::GLX)endif()if(XRT_HAVE_EGL)target_sources(comp_client PRIVATE client/comp_egl_client.c client/comp_egl_client.h)endif()util library ,
XRT_HAVE_VULKAN:ON
1234567891011121314151617181920212223### Util library#if(XRT_HAVE_VULKAN)add_library(comp_util STATICutil/comp_base.hutil/comp_base.cutil/comp_swapchain.hutil/comp_swapchain.cutil/comp_sync.hutil/comp_sync.cutil/comp_vulkan.hutil/comp_vulkan.c)target_link_libraries(comp_utilPUBLIC xrt-interfacesPRIVATE aux_util aux_os aux_vk)target_include_directories(comp_util PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})endif()Render library ,
XRT_HAVE_VULKAN:ON
123456789101112131415161718192021222324252627282930313233343536373839404142### Render library#if(XRT_HAVE_VULKAN)spirv_shaders(SHADER_HEADERSshaders/clear.compshaders/distortion.compshaders/distortion_timewarp.compshaders/mesh.fragshaders/mesh.vertshaders/layer.fragshaders/layer.vertshaders/equirect1.vertshaders/equirect1.fragshaders/equirect2.vertshaders/equirect2.frag)add_library(comp_render STATIC${SHADER_HEADERS}render/comp_buffer.crender/comp_compute.crender/comp_render.hrender/comp_rendering.crender/comp_resources.crender/comp_shaders.crender/comp_util.c)target_link_libraries(comp_renderPUBLIC xrt-interfacesPRIVATE aux_util aux_os aux_vk)target_include_directories(comp_render PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})# Shaders - marked SYSTEM so we get no warningstarget_include_directories(comp_render SYSTEM PRIVATE ${CMAKE_CURRENT_BINARY_DIR})add_subdirectory(shaders)endif()add_subdirectory(shaders)
12345# Copyright 2019, Collabora, Ltd.# SPDX-License-Identifier: BSL-1.0# CMakeLists.txt required for CMake to create the shaders/ directory in the build tree.# Generated shaders will be placed there.如注释所述,需要把整个shaders放在build tree中,因此只能放一个空的CMakeLists.txt
Main library,整个scope比较长,由于我们已经提前知晓:
XRT_FEATURE_COMPOSITOR_MAIN:OFF
XRT_HAVE_XCB:OFF
XRT_HAVE_XLIB:OFF
VK_USE_PLATFORM_ANDROID_KHR:ON
ANDROID:ON
整个段落就被简化为:
1234567891011121314151617181920212223242526272829303132333435363738394041### Main library#if(XRT_FEATURE_COMPOSITOR_MAIN)add_library(comp_main STATICmain/comp_compositor.cmain/comp_compositor.hmain/comp_documentation.hmain/comp_renderer.cmain/comp_renderer.hmain/comp_settings.cmain/comp_settings.hmain/comp_target.hmain/comp_target_swapchain.cmain/comp_target_swapchain.hmain/comp_window.hmain/comp_layer.hmain/comp_layer.cmain/comp_layer_renderer.hmain/comp_layer_renderer.c)target_link_libraries(comp_mainPUBLIC xrt-interfacesPRIVATEaux_utilaux_osaux_vkcomp_utilcomp_render)target_include_directories(comp_main PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})if(ANDROID)target_sources(comp_main PRIVATE main/comp_window_android.c)target_link_libraries(comp_main PRIVATE aux_ogl aux_android)endif()endif()最后是multi client compositor library的部分:
1234567891011121314151617181920#### Multi client compositor library#add_library(comp_multi STATIC multi/comp_multi_compositor.c multi/comp_multi_interface.hmulti/comp_multi_private.h multi/comp_multi_system.c)target_link_libraries(comp_multiPUBLIC xrt-interfacesPRIVATE aux_util aux_os)target_include_directories(comp_multi PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})if(XRT_FEATURE_COMPOSITOR_MAIN)target_link_libraries(comp_main PRIVATE comp_multi)endif()
小结:整个compositor的构建目标是 comp_main
state_trackers
monado/src/xrt/state_trackers/CMakeLists.txt
本来的理解中,state_trackers
是monado runtime的状态机切换中的tracker(待后续代码确认)。
先查看一下state_trackers/CMakeLists.txt
,其中:
XRT_HAVE_OPENGL:OFF
XRT_FEATURE_STEAMVR_PLUGIN:OFF
|
|
因此整个就简化为两句话了:
|
|
oxr
monado/src/xrt/state_trackers/oxr/CMakeLists.txt
,另外我们通过根目录的CMakeLists.txt
已知:
XRT_HAVE_VULKAN:ON
XRT_HAVE_OPENGL:OFF
XRT_HAVE_OPENGLES:ON
XRT_HAVE_XLIB:OFF
XRT_HAVE_EGL:ON
ANDROID:ON
整个CMakeLists.txt可以简化为:
|
|
因此整个target目标为:st_oxr
prober
monado/src/xrt/state_trackers/prober/CMakeLists.txt
同样的,我们已知:
XRT_HAVE_LIBUDEV:OFF
XRT_HAVE_LIBUSB:OFF
XRT_HAVE_OPENCV:OFF
XRT_HAVE_V4L2:OFF
XRT_BUILD_DRIVER_REMOTE:ON
整个CMakeLists可以简化为:
|
|
因此整个target目标为:st_prober
小结:对于state_trackers来说,最终会出现两个target:st_oxr
以及st_prober
targets
monado/src/xrt/targets/CMakeLists.txt
targets在gradle的编译中其实已经有提到了,我们起点的部分是在openxr_android
,最终绕了一圈又回到了这里。
一样的分析流程:
XRT_FEATURE_OPENXR:ON
XRT_HAVE_SDL2:OFF
XRT_FEATURE_SERVICE:OFF
|
|
common
monado/src/xrt/targets/common/CMakeLists.txt
继续分析
XRT_BUILD_DRIVER_ARDUINO
XRT_BUILD_DRIVER_DAYDREAM
XRT_BUILD_DRIVER_DEPTHAI
XRT_BUILD_DRIVER_QWERTY
XRT_BUILD_DRIVER_HDK
XRT_BUILD_DRIVER_HYDRA
XRT_BUILD_DRIVER_NS
XRT_BUILD_DRIVER_ULV2
XRT_BUILD_DRIVER_OHMD
XRT_BUILD_DRIVER_PSMV
XRT_BUILD_DRIVER_PSVR
XRT_BUILD_DRIVER_REALSENSE
XRT_BUILD_DRIVER_VIVE
XRT_BUILD_DRIVER_VF
XRT_BUILD_DRIVER_HANDTRACKING
XRT_BUILD_DRIVER_SURVIVE
XRT_BUILD_DRIVER_ILLIXR
XRT_BUILD_DRIVER_EUROC
整个CMakeLists就会被简化为:
|
|
最终这边会出现的target为:
target_lists
target_instance
target_instance_no_comp
openxr
monado/src/xrt/targets/openxr/CMakeLists.txt
,同样的,我们把预先定义的宏都展开
XRT_FEATURE_SERVICE:OFF
,因为使用的是inProcess模式MSVC:OFF
,因为没有使用microsoft visual c++编译器RUNTIME_BARE_SUFFIX = monado,RUNTIME_PREFIX = ""
,因此RUNTIME_TARGET = openxr_monado
XRT_HAVE_OPENGL:OFF
CMAKE_SYSTEM_NAME:Android
|
|
切记:
add_library(${RUNTIME_TARGET} MODULE target.c libopenxr.def)
targets/openxr定义了一个
openxr_monado
的target,这个部分跟build.gradle的部分联系了起来,在android gradle项目中的最终target就是openxr_monado
123456789productFlavors {inProcess {dimension 'deployment'applicationIdSuffix '.in_process'externalNativeBuild.cmake.arguments += "-DXRT_FEATURE_SERVICE=OFF"externalNativeBuild.cmake.targets "openxr_monado"resValue "string", "app_name", "Monado XR"}
cil
monado/src/xrt/targets/cil/CMakeLists.txt
cil = Common Intermediate Language
,这个模块可以认为是一种用来调试的辅助工具,类似android中am,wm命令
|
|
ipc
monado/src/xrt/ipc/CMakeLists.txt
,ipc的部分顾名思义,应该是进程间通讯会用到的模块,理论上来说应该是outProcess
下会用到的部分。
XRT_HAVE_SYSTEMD:OFF
RT_LIBRARY:OFF
|
|
这边所有的target为:
ipc_shared
ipc_client
ipc_server
ipc_android
Target link
根据之前对整个CMakeLists的阅读,我们可以厘清整个targe的link链,但是我们需要的link是哪个?这个就需要回到build.gradle
里去了。
还记得monado/src/xrt/targets/openxr_android/build.gradle
吗?其中对于inProcess
和outProcess
的
|
|
target:openxr_monado
从build.gradle
中针对inProcess
的flavor,我们可以看到CMakeLists的交付件为:openxr_monado
,我们根据之前的link list来反溯一下需要用到哪些模块。
首先是整个target的入口monado/src/xrt/targets/openxr/CMakeLists.txt
:add_library(${RUNTIME_TARGET} MODULE target.c libopenxr.def)
add_library(openxr_monado MODULE target.c libopenxr.def)
其中的link依赖如下:
|
|
因此target:
openxr_monado
依赖路径:aux_vk,aux_os,aux_util,aux_math,st_oxr,st_prober,target_lists,target_instance,comp_main,comp_client,oxr_sdl2graph TD openxr_monado --> st_oxr openxr_monado --> st_prober openxr_monado --> target_lists openxr_monado --> target_instance openxr_monado --> comp_main openxr_monado --> comp_client openxr_monado --> aux_vk openxr_monado --> aux_os openxr_monado --> aux_util openxr_monado --> aux_math
依赖关系
我们挨个展开来看一下每个库的依赖关系
aux_vk
aux_vk:aux_os,aux_util,Vulkan::Vulkan,aux_android,android
graph TD aux_vk --> aux_os aux_vk --> aux_util aux_vk --> Vulkan::Vulkan aux_vk --> aux_android aux_vk --> android
aux_os
aux_os:aux-includes,xrt-pthreads
graph TD aux_os --> aux-includes aux_os --> xrt-pthreads
aux_util
aux_util:aux-includes,xrt-pthreads,aux_generated_bindings,aux_math,${JPEG_LIBRARIES},xrt-external-cjson,${ANDROID_LOG_LIBRARY}
graph TD aux_util --> aux-includes aux_util --> xrt-pthreads aux_util --> aux_generated_bindings aux_util --> aux_math aux_util --> JPEG_LIBRARIES aux_util --> xrt-external-cjson aux_util --> ANDROID_LOG_LIBRARY
aux_math
aux_math:aux-includes,aux_util
graph TD aux_math --> aux-includes aux_math --> aux_util
st_oxr
st_oxr:Vulkan::Vulkan,aux_ogl,aux_android
graph TD st_oxr --> Vulkan::Vulkan st_oxr --> aux_ogl st_oxr --> aux_android
st_prober
st_prober:xrt-interfaces,drv_remote,drv_includes,drv_multi,aux_util,aux_os,aux_tracking
graph TD st_prober --> xrt-interfaces st_prober --> drv_remote st_prober --> drv_includes st_prober --> drv_multi st_prober --> aux_util st_prober --> aux_os st_prober --> aux_tracking
target_lists
target_lists:xrt-interfaces,aux_util,drv_includes,drv_dummy,drv_remote,drv_android,drv_multi,drv_wmr
graph TD target_lists --> xrt-interfaces target_lists --> aux_util target_lists --> drv_includes target_lists --> drv_dummy target_lists --> drv_remote target_lists --> drv_android target_lists --> drv_multi target_lists --> drv_wmr
target_instance
target_instance:xrt-interfaces,aux_util,st_prober,target_lists,comp_main,drv_includes
graph TD target_instance --> xrt-interfaces target_instance --> aux_util target_instance --> st_prober target_instance --> target_lists target_instance --> comp_main target_instance --> drv_includes
comp_main
comp_main:xrt-interfaces,aux_util,aux_os,aux_vk,comp_util,comp_render,aux_ogl,aux_android,comp_multi
graph TD comp_main --> xrt-interfaces comp_main --> aux_util comp_main --> aux_os comp_main --> aux_vk comp_main --> comp_util comp_main --> comp_render comp_main --> aux_ogl comp_main --> aux_android comp_main --> comp_multi
comp_client
comp_client:xrt-interfaces,aux_util,aux_vk,aux_ogl
graph TD comp_client --> xrt-interfaces comp_client --> aux_util comp_client --> aux_vk comp_client --> aux_ogl
oxr_sdl2
oxr_sdl2:aux_util,aux_ogl
graph TD oxr_sdl2 --> aux_util oxr_sdl2 --> aux_ogl
二级依赖
aux_generated_bindings
aux_generated_bindings:xrt-interfaces,aux_util
graph TD aux_generated_bindings --> xrt-interfaces aux_generated_bindings --> aux_util
comp_util
comp_util:xrt-interfaces,aux_util,aux_os,aux_vk
graph TD comp_util --> xrt-interfaces comp_util --> aux_util comp_util --> aux_os comp_util --> aux_vk
aux_ogl
aux_ogl:aux-includes,xrt-external-glad,EGL::EGL
graph TD aux_ogl --> aux-includes aux_ogl --> xrt-external-glad aux_ogl --> EGL::EGL
aux_android
aux_android:aux_util,${ANDROID_LIBRARY},${ANDROID_LOG_LIBRARY},xrt-external-jni-wrap,xrt-external-jnipp,android_app_glue
graph TD aux_android --> aux_util aux_android --> ANDROID_LIBRARY aux_android --> ANDROID_LOG_LIBRARY aux_android --> xrt-external-jni-wrap aux_android --> xrt-external-jnipp aux_android --> android_app_glue
comp_multi
comp_multi:xrt-interfaces,aux_util,aux_os
graph TD comp_multi --> xrt-interfaces comp_multi --> aux_util comp_multi --> aux_os
aux_tracking
aux_tracking:aux-includes,xrt-external-cjson,aux_math,aux_util,xrt-external-flexkalman,xrt-external-hungarian
graph TD aux_tracking --> aux-includes aux_tracking --> xrt-external-cjson aux_tracking --> aux_math aux_tracking --> aux_util aux_tracking --> xrt-external-flexkalman aux_tracking --> xrt-external-hungarian
drv_multi
drv_multi:xrt-interfaces,aux_util
graph TD drv_multi --> xrt-interfaces drv_multi --> aux_util
drv_remote
drv_remote:xrt-interfaces,aux_util
graph TD drv_remote --> xrt-interfaces drv_remote --> aux_util
drv_android
drv_android:xrt-interfaces,aux_util,aux_os,aux_android,${ANDROID_LIBRARY}
graph TD drv_android --> xrt-interfaces drv_android --> aux_util drv_android --> aux_os drv_android --> aux_android drv_android --> ANDROID_LIBRARY
drv_wmr
drv_wmr:xrt-interfaces,aux_util,aux_math,aux_tracking,xrt-external-cjson
graph TD drv_wmr --> xrt-interfaces drv_wmr --> aux_util drv_wmr --> aux_math drv_wmr --> aux_tracking drv_wmr --> xrt-external-cjson
comp_render
comp_render:aux_util,aux_os,aux_vk
graph TD comp_render --> aux_util comp_render --> aux_os comp_render --> aux_vk
整体结构
这个时候通过展开这样的一个拓扑关系树,我们就可以得到整个openxr_monado的编译依赖了。
flowchart LR openxr_monado --> st_oxr openxr_monado --> st_prober openxr_monado --> target_lists openxr_monado --> target_instance openxr_monado --> comp_main openxr_monado --> comp_client openxr_monado --> aux_vk openxr_monado --> aux_os openxr_monado --> aux_util openxr_monado --> aux_math aux_vk --> aux_os aux_vk --> aux_util aux_vk --> Vulkan::Vulkan aux_vk --> aux_android aux_vk --> android aux_os --> aux-includes aux_os --> xrt-pthreads aux_util --> aux-includes aux_util --> xrt-pthreads aux_util --> aux_generated_bindings aux_util --> aux_math aux_util --> JPEG_LIBRARIES aux_util --> xrt-external-cjson aux_util --> ANDROID_LOG_LIBRARY aux_math --> aux-includes aux_math --> aux_util st_oxr --> Vulkan::Vulkan st_oxr --> aux_ogl st_oxr --> aux_android st_prober --> xrt-interfaces st_prober --> drv_remote st_prober --> drv_includes st_prober --> drv_multi st_prober --> aux_util st_prober --> aux_os st_prober --> aux_tracking target_lists --> xrt-interfaces target_lists --> aux_util target_lists --> drv_includes target_lists --> drv_dummy target_lists --> drv_remote target_lists --> drv_android target_lists --> drv_multi target_lists --> drv_wmr target_instance --> xrt-interfaces target_instance --> aux_util target_instance --> st_prober target_instance --> target_lists target_instance --> comp_main target_instance --> drv_includes comp_main --> xrt-interfaces comp_main --> aux_util comp_main --> aux_os comp_main --> aux_vk comp_main --> comp_util comp_main --> comp_render comp_main --> aux_ogl comp_main --> aux_android comp_main --> comp_multi comp_client --> xrt-interfaces comp_client --> aux_util comp_client --> aux_vk comp_client --> aux_ogl oxr_sdl2 --> aux_util oxr_sdl2 --> aux_ogl aux_generated_bindings --> xrt-interfaces aux_generated_bindings --> aux_util comp_util --> xrt-interfaces comp_util --> aux_util comp_util --> aux_os comp_util --> aux_vk aux_ogl --> aux-includes aux_ogl --> xrt-external-glad aux_ogl --> EGL::EGL aux_android --> aux_util aux_android --> ANDROID_LIBRARY aux_android --> ANDROID_LOG_LIBRARY aux_android --> xrt-external-jni-wrap aux_android --> xrt-external-jnipp aux_android --> android_app_glue comp_multi --> xrt-interfaces comp_multi --> aux_util comp_multi --> aux_os aux_tracking --> aux-includes aux_tracking --> xrt-external-cjson aux_tracking --> aux_math aux_tracking --> aux_util aux_tracking --> xrt-external-flexkalman aux_tracking --> xrt-external-hungarian drv_multi --> xrt-interfaces drv_multi --> aux_util drv_remote --> xrt-interfaces drv_remote --> aux_util drv_android --> xrt-interfaces drv_android --> aux_util drv_android --> aux_os drv_android --> aux_android drv_android --> ANDROID_LIBRARY drv_wmr --> xrt-interfaces drv_wmr --> aux_util drv_wmr --> aux_math drv_wmr --> aux_tracking drv_wmr --> xrt-external-cjson comp_render --> aux_util comp_render --> aux_os comp_render --> aux_vk
总结
整个
Android
相关的工程编译是从monado/src/xrt/targets/openxr_android/build.gralde
开始的Android
工程在Native端的build target:openxr_monado
,交付件:libopenxr_monado.so
,该target定义在:monado/src/xrt/targets/openxr/CMakeLists.txt
编译过程中某些config开关可以直接去查看CMakeCache文件,以arm64-v8a为例,中间文件在如下地址:
monado/src/xrt/targets/openxr_android/.cxx/cmake/inProcessDebug/arm64-v8a/CMakeCache.txt
跟graphic相关的库有
aux_vk
,aux_ogl
,这一部分的定义在:monado/src/xrt/auxiliary/CMakeLists.txt
- 代码部分在:
monado/src/xrt/auxiliary/ogl
,monado/src/xrt/auxiliary/vk
- 代码部分在:
跟android相关部分
aux_android
,这一部分的定义在:monado/src/xrt/auxiliary/CMakeLists.txt
- 代码的部分在:
monado/src/xrt/auxiliary/android
- 代码的部分在:
支持的设备是在
target_lists
,这个部分需要再去看代码确认一下仅仅是驱动,还是类似hal的中间层- 其中
drv_android
由monado/src/xrt/drivers/android/
下的文件编译而成,其中包含android_sensor.c
,主要是做了g sensor数据的获取,以及3dof算法
- 其中
comp_xxx
的部分应该是重中之中,其中牵扯到不少都是VR核心的渲染部分?这个需要后续深入去看compositor
的流程是什么,大致的框架comp_client
,comp_main
,comp_multi
之间是什么关系
最终是关于opengles和vulkan的,这个部分的重点应该是落在实现上,而不是应用上,所以后续需要理解的是各个命令的具体实现,GPU到底做了什么。